package com.huanletao.proxy.cglib;

import com.huanletao.annotation.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * <p>
 * </p>
 * package: com.huanletao.proxy.cglib
 * description:
 * className: AnnotationMethodNameAdvisor
 * author:  踏雪无痕
 * copyright: Copyright (c) 2022/9/30 22:25
 * since: 1.0.0
 */
public class AnnotationMethodNameAdvisor implements Advisor {
    private Interceptor interceptor;

    private Class<? extends Annotation> annotationType;

    public AnnotationMethodNameAdvisor(Interceptor interceptor) {
        this.interceptor = interceptor;
    }

    public void setInterceptor(Interceptor interceptor) {
        this.interceptor = interceptor;
    }

    public Class<? extends Annotation> getAnnotationType() {
        return annotationType;
    }

    public void setAnnotationType(Class<? extends Annotation> annotationType) {
        this.annotationType = annotationType;
    }

    @Override
    public boolean matches(Method method, Class<?> targetClass) {
        return AnnotationUtils.hasAnnotation(method, annotationType) ||
                AnnotationUtils.hasAnnotation(targetClass, annotationType);
    }

    @Override
    public Interceptor getInterceptor() {
        return interceptor;
    }
}
